package com.sojson.project.controller;

import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import javax.annotation.Resource;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;

import com.sojson.project.entity.po.Auth;
import com.sojson.project.service.AuthService;
import com.sojson.result.Result;

/**
 * 权限表控制器
 * 
 * @author liu
 * @date 2021-03-16
 */
// @Api(tags = "权限表管理")
// @RestController
// @RequestMapping(value = "/auth")
public class AuthController {

    @Resource
    private AuthService authServiceImpl;

    /**
     * 单条插入
     * 
     * @param auth
     * @return
     * @throws SQLException
     */
    @PostMapping("/insert")
    public Object insert(@RequestBody Auth auth) throws SQLException {
        authServiceImpl.insert(auth);
        return Result.success();
    }

    /**
     * 批量插入
     * 
     * @param auth
     * @return
     * @throws SQLException
     */
    @PostMapping("/insertList")
    public Object insertList(@RequestBody Auth auth) throws SQLException {
        return Result.success(authServiceImpl.insertList(auth));
    }

    /**
     * 通过对象批量删除(物理删除)
     * 
     * @param auth
     * @return
     * @throws SQLException
     */
    @PostMapping("/deleteByDto")
    public Object deleteByDto(@RequestBody Auth auth) throws SQLException {
        return Result.success(authServiceImpl.deleteByDto(auth));
    }

    /**
     * 统计全部数量
     * 
     * @return
     * @throws SQLException
     */
    @GetMapping("/countAll")
    public Object countAll() throws SQLException {
        int countAll = authServiceImpl.countAll();
        return Result.success(countAll);
    }

    /**
     * 查询所有
     * 
     * @return
     * @throws SQLException
     */
    @GetMapping("/findAll")
    public Object findAll() throws SQLException {
        List<Auth> findAll = authServiceImpl.findAll();
        return Result.success(findAll);
    }

    /**
     * 根据对象统计数量
     * 
     * @param auth
     * @return
     * @throws SQLException
     */
    @PostMapping("/countByDto")
    public Object countByDto(@RequestBody Auth auth) throws SQLException {
        int countByDto = authServiceImpl.countByDto(auth);
        return Result.success(countByDto);
    }

    /**
     * 根据对象查询
     * 
     * @param auth
     * @return
     * @throws SQLException
     */
    @PostMapping("/findByDto")
    public Object findByDto(@RequestBody Auth auth) throws SQLException {
        List<Auth> findByDto = authServiceImpl.findByDto(auth);
        return Result.success(findByDto);
    }

    /**
     * 通过id删除(物理删除)
     * 
     * @param id
     * @return
     * @throws SQLException
     */
    @PostMapping("/deleteById")
    public Object deleteById(Integer id) throws SQLException {
        authServiceImpl.deleteById(id);
        return Result.success();
    }

    /**
     * 通过id列表删除(物理删除)
     * 
     * @param ids
     * @return
     * @throws SQLException
     */
    @PostMapping("/deleteByIdList")
    public Object deleteByIdList(@RequestParam("ids[]") ArrayList<Integer> ids) throws SQLException {
        return Result.success(authServiceImpl.deleteByIdList(ids));
    }

    /**
     * 通过id更新(全部更新)
     * 
     * @param auth
     * @return
     * @throws SQLException
     */
    @PostMapping("/updateById")
    public Object updateById(@RequestBody Auth auth) throws SQLException {
        authServiceImpl.updateById(auth);
        return Result.success();
    }

    /**
     * 通过id列表更新(全部更新)(更新内容相同)
     * 
     * @param auth
     * @return
     * @throws SQLException
     */
    @PostMapping("/updateStaticByIdList")
    public Object updateStaticByIdList(@RequestBody Auth auth) throws SQLException {
        return Result.success(authServiceImpl.updateStaticByIdList(auth));
    }

    /**
     * 通过id列表更新(全部更新)(更新内容不相同)
     * 
     * @param auth
     * @return
     * @throws SQLException
     */
    @PostMapping("/updateChangeByIdList")
    public Object updateChangeByIdList(@RequestBody Auth auth) throws SQLException {
        return Result.success(authServiceImpl.updateChangeByIdList(auth));
    }

    /**
     * 通过id更新(局部更新)
     * 
     * @param auth
     * @return
     * @throws SQLException
     */
    @PostMapping("/updatePartialById")
    public Object updatePartialById(@RequestBody Auth auth) throws SQLException {
        authServiceImpl.updatePartialById(auth);
        return Result.success();
    }

    /**
     * 通过id列表更新(局部更新)(更新内容相同)
     * 
     * @param auth
     * @return
     * @throws SQLException
     */
    @PostMapping("/updateStaticPartialByIdList")
    public Object updateStaticPartialByIdList(@RequestBody Auth auth) throws SQLException {
        return Result.success(authServiceImpl.updateStaticPartialByIdList(auth));
    }

    /**
     * 通过id列表更新(局部更新)(更新内容不相同)
     * 
     * @param auth
     * @return
     * @throws SQLException
     */
    @PostMapping("/updateChangePartialByIdList")
    public Object updateChangePartialByIdList(@RequestBody Auth auth) throws SQLException {
        return Result.success(authServiceImpl.updateChangePartialByIdList(auth));
    }

    /**
     * 通过id查询
     * 
     * @param id
     * @return
     * @throws SQLException
     */
    @GetMapping("/findById")
    public Object findById(Integer id) throws SQLException {
        Auth findById = authServiceImpl.findById(id);
        return Result.success(findById);
    }

    /**
     * 通过id列表查询
     * 
     * @param ids
     * @return
     * @throws SQLException
     */
    @GetMapping("/findByIdList")
    public Object findByIdList(@RequestParam("ids[]") ArrayList<Integer> ids) throws SQLException {
        ArrayList<Auth> findByIdList = authServiceImpl.findByIdList(ids);
        return Result.success(findByIdList);
    }

    /**
     * 通过对象查询id列表
     * 
     * @param auth
     * @return
     * @throws SQLException
     */
    @PostMapping("/findIdByDto")
    public Object findIdByDto(@RequestBody Auth auth) throws SQLException {
        ArrayList<Integer> findIdByDto = authServiceImpl.findIdByDto(auth);
        return Result.success(findIdByDto);
    }

    /**
     * 清空数据(物理清空)
     * 
     * @return
     * @throws SQLException
     */
    @PostMapping("/clear")
    public Object clear() throws SQLException {
        authServiceImpl.clear();
        return Result.success();
    }

}